#include "init.hpp"

Init::Init():board(),id_current_player(0)
{
    init_list_player();
    init_list_treasure();
}

void Init::init_list_player()
{
    unsigned int nb_player(0);
    string answer("");
    Player tmp;

    do
    {
        cout << "Number of players ? ( between 2 and 4 )" << endl;
        cin >> answer;

        if(answer.compare("2") == 0)
        {
            nb_player=2;
            break;
        }
        else if(answer.compare("3") == 0)
        {
            nb_player=3;
            break;
        }
        else if(answer.compare("4") == 0)
        {
            nb_player=4;
            break;
        }
    }
    while(true);

    for(unsigned int cpt_player(0) ; cpt_player < nb_player ; ++cpt_player)
    {
        cout << "Give me your name : " << endl;
        cin >> answer;

        tmp.unique_id=cpt_player;
        tmp.name=answer;

        switch(cpt_player)
        {
        case 0:
            tmp.x=tmp.y=0;
            break;

        case 1:
            tmp.x=tmp.y=6;
            break;

        case 2:
            tmp.x=0;
            tmp.y=6;
            break;

        case 3:
            tmp.x=6;
            tmp.y=0;
            break;
        }

        board.plate[tmp.x][tmp.y].have_piece=true;
        list_player.push_back(tmp);
    }
}

void Init::init_list_treasure()
{
    Treasure tmp;
    unsigned int cpt_player(0);

    for(auto & l_p:list_player)
    {
        for(unsigned int cpt_tresure(0) ; cpt_tresure < NB_TREASURE ; ++cpt_tresure)
        {
            do
            {
                tmp.set_all(cpt_player*NB_TREASURE+cpt_tresure,random()%SIZE,random()%SIZE);
            }
            while(board.is_in_same_position(tmp) == true);

            board.t.push_back(tmp);
            l_p.list_treasure.push_back(tmp);
        }

        ++cpt_player;
    }
}